package adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.List;

import base.MyApplcation;
import bean.ShouYeBean;
import util.utls.Const;
import util.utls.SPUtils;
import util.utls.XImageLoader;
import widget.LoweImageView;


/**
 * 首页
 */
public class ShouYeAdapter extends android.widget.BaseAdapter{
    List<ShouYeBean.Products> list;
    Activity activity;

    public ShouYeAdapter(Activity activity, List<ShouYeBean.Products> list) {
        this.activity = activity;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (holder == null) {
            holder=new ViewHolder();
            convertView = LayoutInflater.from(activity).inflate(R.layout.item_goods, null);
            holder.goods_img= (LoweImageView) convertView.findViewById(R.id.goods_img);
            holder.good_title= (TextView) convertView.findViewById(R.id.good_title);
            holder.good_price= (TextView) convertView.findViewById(R.id.good_price);
            holder.goods_tehui= (ImageView) convertView.findViewById(R.id.goods_tehui);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        XImageLoader.load(Const.IMAGE_HEAD + list.get(position).getImg(),
                holder.goods_img);
        holder.good_title.setText(list.get(position).getName());
        if (list.get(position).getPrice().equals("")) {

        }else {
            holder.good_price.setText("¥" + Double.parseDouble(list.get(position).getPrice()) / 100);
        }
        String uid = (String) SPUtils.get(MyApplcation.ctx, null, Const.JiaoBiao, "");
        XImageLoader.load(Const.IMAGE_HEAD + uid,holder.goods_tehui);

        return convertView;
    }

    public static class ViewHolder {
        LoweImageView goods_img;
        ImageView goods_tehui;
        TextView good_title, good_price;
    }
}
